package assets_withdraw

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"
	"github.com/zeromicro/go-zero/core/logx"
)

type AssetsWithDrawCollectionBankFindLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// b端提现管理--代收三方银行--查询
func NewAssetsWithDrawCollectionBankFindLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AssetsWithDrawCollectionBankFindLogic {
	return &AssetsWithDrawCollectionBankFindLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AssetsWithDrawCollectionBankFindLogic) AssetsWithDrawCollectionBankFind(req *types.AssetsWithDrawCollectionBankFindReq) (resp *types.AssetsWithDrawCollectionBankFindRes, err error) {
	// todo: add your logic here and delete this line
	rpc_req := &rpc.GetWithDrawCollectionBankRequest{
		Bankname:       req.BankName,
		CollectionName: req.CollectionName,
		Page: &rpc.Page{
			Page:      req.Page.Page,
			PageSize:  req.Page.PageSize,
			SortOrder: req.Page.SortOrder,
		},
	}

	// 发送请求
	rpc_resp, err := l.svcCtx.AssetsRpc.TenantChannel.WithdrawCollectionBankListPage(l.ctx, rpc_req)
	if err != nil {
		logx.Errorf("Call ModifyVipLevelInfos error: %v", err)
		return nil, err
	}

	// 处理请求返回的结果
	// 解析、组合数据
	resp = &types.AssetsWithDrawCollectionBankFindRes{}
	for _, d := range rpc_resp.Data {
		resp.Data = append(resp.Data, types.WithDrawCollectionBank{
			Id:             d.Id,
			BankName:       d.BankName,
			BankCode:       d.BankCode,
			CollectionName: d.CollectionName,
			Status:         d.Status,
		})
	}
	resp.Count = rpc_resp.ResHead.Count
	return
}
